/**
 * prdTrace管理初始化
 */
var BusPrdTrace = {
    id: "BusPrdTraceTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
BusPrdTrace.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '结束值', field: 'prdTraceMaximum', visible: true, align: 'center', valign: 'middle'},
            {title: '开始值', field: 'prdTraceMinimum', visible: true, align: 'center', valign: 'middle'},
            {title: '数量', field: 'prdTraceBatchcount', visible: true, align: 'center', valign: 'middle'},
            {title: '产品id', field: 'prdId', visible: true, align: 'center', valign: 'middle'},
            {title: '产品名称', field: 'prdName', visible: true, align: 'center', valign: 'middle'},
            {title: '公司名称', field: 'comName', visible: true, align: 'center', valign: 'middle'},
            {title: '创建人', field: 'maintainer', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createtime', visible: true, align: 'center', valign: 'middle'},
            {title: '下载二维码生成文件', field: 'qrCodeFileUrl', visible: true, align: 'center', valign: 'middle'
                ,formatter: function (value, row, index) {
                    //return '<a href="#" onclick="BusPrdTrace.download(\''+row.qrCodeFileName+'\')">下载</a>';
                return '<a href="/busPrdTrace/download?qrCodeFileName='+row.qrCodeFileName+'" >下载</a>';
            }}
    ];
};
BusPrdTrace.download =function(qrCodeFileName) {
    console.log(qrCodeFileName);
    var ajax = new $ax(Feng.ctxPath + "/busPrdTrace/download", function (data) {

    }, function (data) {
        Feng.error("下载失败" + data.responseJSON.message + "!");
    });
    ajax.set("qrCodeFileName",qrCodeFileName);
    ajax.start();
}
/**
 * 检查是否选中
 */
BusPrdTrace.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        BusPrdTrace.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加prdTrace
 */
BusPrdTrace.openAddBusPrdTrace = function () {
    var index = layer.open({
        type: 2,
        title: '添加prdTrace',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/busPrdTrace/busPrdTrace_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看prdTrace详情
 */
BusPrdTrace.openBusPrdTraceDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'prdTrace详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/busPrdTrace/busPrdTrace_update/' + BusPrdTrace.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除prdTrace
 */
BusPrdTrace.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/busPrdTrace/delete", function (data) {
            Feng.success("删除成功!");
            BusPrdTrace.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("busPrdTraceId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询prdTrace列表
 */
BusPrdTrace.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    BusPrdTrace.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = BusPrdTrace.initColumn();
    var table = new BSTable(BusPrdTrace.id, "/busPrdTrace/list", defaultColunms);
    table.setPaginationType("client");
    BusPrdTrace.table = table.init();
});
